package singleton;

/**
 * 懒汉式（双重检验加锁），线程安全
 * （1）为么两层判空？
 *
 * （2）为么使用volatile修饰？
 */
public class SingleTon5 {

    private static SingleTon5 instance;

    private SingleTon5(){

    }

    public static SingleTon5 getInstance(){
        if(null == instance){
            try{
                Thread.sleep(1);
            }catch (Exception e){
                e.getMessage();
            }
            synchronized(SingleTon5.class){
                if(null == instance){
                    instance = new SingleTon5();
                }
            }
        }
        return instance;
    }
}
